package com.sugon.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.DevPlanOptionDao;
import com.sugon.entity.DevPlanOptionEntity;
import com.sugon.service.DevPmRuleItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 维护规程选项关联表Service实现类
 *
 * @author sugon
 * @date 2019-07-18 15:31:48
 */
@Service("devPlanOptionService")
public class DevPlanOptionServiceImpl implements DevPmRuleItemService {
    @Autowired
    private DevPlanOptionDao devPlanOptionDao;

    /**
     * queryObject
     *
     * @param id 主键
     * @return
     */
    @Override
    public DevPlanOptionEntity queryObject(String id) {
        return devPlanOptionDao.queryObject(id);
    }

    /**
     * queryList
     *
     * @param map 参数
     * @return
     */
    @Override
    public List<DevPlanOptionEntity> queryList(Map<String, Object> map) {
        return devPlanOptionDao.queryList(map);
    }

    /**
     * queryTotal
     *
     * @param map 参数
     * @return
     */
    @Override
    public int queryTotal(Map<String, Object> map) {
        return devPlanOptionDao.queryTotal(map);
    }

    /**
     * save
     *
     * @param devPlanOption 实体
     * @return
     */
    @Override
    public int save(DevPlanOptionEntity devPlanOption) {
        devPlanOption.setId(RandomUtil.randomString(32));
        return devPlanOptionDao.save(devPlanOption);
    }

    /**
     * update
     *
     * @param devPlanOption 实体
     * @return
     */
    @Override
    public int update(DevPlanOptionEntity devPlanOption) {
        return devPlanOptionDao.update(devPlanOption);
    }

    /**
     * delete
     *
     * @param id
     * @return
     */
    @Override
    public int delete(String id) {
        return devPlanOptionDao.delete(id);
    }

    /**
     * deleteBatch
     *
     * @param ids
     * @return
     */
    @Override
    public int deleteBatch(String[] ids) {
        return devPlanOptionDao.deleteBatch(ids);
    }

    /**
     * isHave
     *
     * @param planId
     * @param opId
     * @return
     */
    @Override
    public int isHave(String planId, String opId) {
        Map<String, Object> param = new HashMap<>(2);
        param.put("planId", planId);
        param.put("opId", opId);
        return devPlanOptionDao.queryTotal(param);
    }

    /**
     * getByPlanId
     *
     * @param planId 规程ID
     * @return
     */
    @Override
    public List<DevPlanOptionEntity> getByPlanId(String planId) {
        Map<String, Object> param = new HashMap<>(2);
        param.put("planId", planId);
        return devPlanOptionDao.queryList(param);
    }
}
